package com.easybuy.service.CategoryService;

import com.easybuy.Tools.Page;
import com.easybuy.dao.CategoryMapper;
import com.easybuy.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    public List<Category> selectSanCeng(){
        return categoryMapper.selectSanCeng();
    }

    public Category selectById(int id) {
        return categoryMapper.selectById(id);
    }

    @Override
    public Category selectByName(String name) {
        return categoryMapper.selectByName(name);
    }

    public List<Category> selectByParentId(int id) {
        return categoryMapper.selectByParentId(id);
    }

    public List<String> selectNames(int id){
        List list=new ArrayList();
        for(int i=0;id!=0;i++){
            Category category=categoryMapper.selectById(id);
            String name=category.getName();
            list.add(name);
            id=category.getParentId();
        }
        return list;
    }

    @Override
    public Page allCategorys(Page page) {
        page.setPageCount(categoryMapper.allCount());
        page.setList(categoryMapper.allCategorys(page));
        return page;
    }

    @Override
    public int addCategory(Category category) {
        return categoryMapper.addCategory(category);
    }

    @Override
    public int deleCategory(int id) {
        return categoryMapper.deleCategory(id);
    }

    @Override
    public int updateCategory(Category category) {
        return categoryMapper.updateCategory(category);
    }

    @Override
    public List getCategoryBytype(int type) {
        return categoryMapper.getCategoryBytype(type);
    }


}
